/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package functions;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import model.Database;
import model.Distributor;
import model.Sklad;

/**
 *
 * @author JArik
 */
public class Sklads {


    public static int addNewSklad(Sklad sklad) throws SQLException {
        Database db = new Database();
        int res = 0;
        ResultSet set = db.insertDBInfo("INSERT INTO sklad_names(name,descr) " +
                                        "VALUES('"+sklad.getName()+"','"+sklad.getDescr()+"' )");
        if(set.next())
          res = set.getInt(1);
        db.closeStatement();
        return res;
    }

    public static ArrayList getByName(String sName) throws SQLException {
        Database db = new Database();
        ResultSet set = db.getDBInfo(
                "id,name,descr", "sklad_names","name LIKE '%"+sName+"%' ORDER BY name DESC ");
        ArrayList<Sklad> res = new ArrayList<Sklad>();
        while(set.next())
        {
            Sklad skl = new Sklad();
            skl.setId(set.getInt("id"));
            skl.setName(set.getString("name"));
            skl.setDescr(set.getString("descr"));
            res.add(skl);
        }
        db.closeStatement();
        return res;
    }

}
